//
//  TTCoreGeometry.m
//  Tint
//
//  Created by Kevin Wu on 2/22/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "TTCoreGeometry.h"


#pragma mark - Angle

CGFloat TTDegreesToRadians(CGFloat degrees)
{
    return ( M_PI * degrees / 180.0 );
}

CGFloat TTRadiansToDegrees(CGFloat radians)
{
    return ( radians * 180.0 / M_PI );
}



#pragma mark - Point

CGPoint TTPointMake(CGFloat x, CGFloat y)
{
    CGPoint point;
    point.x = round(x);
    point.y = round(y);
    return point;
}

CGPoint TTPointSame(CGFloat x)
{
    return TTPointMake(x, x);
}


CGPoint TTPointCopy(CGPoint point)
{
    return TTPointMake(point.x, point.y);
}

CGPoint TTPointSetX(CGPoint point, CGFloat x)
{
    return TTPointMake(x, point.y);
}

CGPoint TTPointSetY(CGPoint point, CGFloat y)
{
    return TTPointMake(point.x, y);
}



#pragma mark - Size

CGSize TTSizeMake(CGFloat width, CGFloat height)
{
    CGSize size;
    size.width = round(width);
    size.height = round(height);
    return size;
}

CGSize TTSizeSquare(CGFloat width)
{
    return TTSizeMake(width, width);
}


CGSize TTSizeCopy(CGSize size)
{
    return TTSizeMake(size.width, size.height);
}

CGSize TTSizeSetWidth(CGSize size, CGFloat width)
{
    return TTSizeMake(width, size.height);
}

CGSize TTSizeSetHeight(CGSize size, CGFloat height)
{
    return TTSizeMake(size.width, height);
}



#pragma mark - Rect

CGRect TTRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
    CGRect rect;
    rect.origin.x = round(x);
    rect.origin.y = round(y);
    rect.size.width = round(width);
    rect.size.height = round(height);
    return rect;
}

CGRect TTRectWithW(CGFloat width)
{
    return TTRectMake(0.0, 0.0, width, width);
}

CGRect TTRectWithWH(CGFloat width, CGFloat height)
{
    return TTRectMake(0.0, 0.0, width, height);
}

CGRect TTRectWithSize(CGSize size)
{
    return TTRectMake(0.0, 0.0, size.width, size.height);
}


CGRect TTRectCopy(CGRect rect)
{
    return TTRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}

CGRect TTRectSetX(CGRect rect, CGFloat x)
{
    return TTRectMake(x, rect.origin.y, rect.size.width, rect.size.height);
}

CGRect TTRectSetY(CGRect rect, CGFloat y)
{
    return TTRectMake(rect.origin.x, y, rect.size.width, rect.size.height);
}

CGRect TTRectSetWidth(CGRect rect, CGFloat width)
{
    return TTRectMake(rect.origin.x, rect.origin.y, width, rect.size.height);
}

CGRect TTRectSetHeight(CGRect rect, CGFloat height)
{
    return TTRectMake(rect.origin.x, rect.origin.y, rect.size.width, height);
}

CGRect TTRectSetOrigin(CGRect rect, CGPoint point)
{
    return TTRectMake(point.x, point.y, rect.size.width, rect.size.height);
}

CGRect TTRectSetSize(CGRect rect, CGSize size)
{
    return TTRectMake(rect.origin.x, rect.origin.y, size.width, size.height);
}

